<?php
session_start();
include_once('../model/DealerDAO.php');

$result = "false";

if(isset($_SESSION['taichinhondealer'])) {
	$email = $_SESSION['taichinhondealer'];
	if(isset($_POST['act'])) {
		$act = $_POST['act'];
		if($act == "updainfo") {
			if(isset($_POST['namere']) && isset($_POST['gend']) && isset($_POST['birthdayre']) && isset($_POST['phonere']) && isset($_POST['homephonere']) && isset($_POST['addressre']) && isset($_POST['provicere']) && isset($_POST['dvct']) && isset($_POST['dcct']) && isset($_POST['gtcv']) && isset($_POST['gtknlv']) && isset($_POST['stk']) && isset($_POST['ngh'])) {
				$name = $_POST['namere'];
				$gender = $_POST['gend'];
				$dayofbirth = strtotime($_POST['birthdayre']);
				$mobile = $_POST['phonere'];
				$homephone = $_POST['homephonere'];
				$address = $_POST['addressre'];
				$province = $_POST['provicere'];
				$dvct = $_POST['dvct'];
				$dcct = $_POST['dcct'];
				$gtcv = $_POST['gtcv'];
				$gtknlv = $_POST['gtknlv'];
				$codebank = $_POST['stk'];
				$bank = $_POST['ngh'];
				
				if(updateDealer($email, $name, $gender, $dayofbirth, $mobile, $homephone, $address, $province, $dvct, $dcct, $gtcv, $gtknlv, $codebank, $bank) == true) {
					$result = 'true';
				}
			}
		} else if($act == "updainfopas") {
			if(isset($_POST['passoldre']) && isset($_POST['passnewre'])) {
				$passold = $_POST['passoldre'];
				$passnew = $_POST['passnewre'];
				
				if(checkLoginRegis($email, md5($passold)) == true) {
					if(updatePasswordDealer($email, md5($passnew)) == true) {
						$result = "true";
					}
				} else {
					$result = "notavali";
				}
			}
		}
	}
}

echo json_encode($result);
?>